<#include "../../common/_home.ftl">
<@html>
<@head>
	<link rel="stylesheet" type="text/css" href="media/css/glyphicons.css">
	<script>
		window.UEDITOR_HOME_URL = "${basePath}ueditor/";
	</script>
	<script type="text/javascript" src="/js/angular.min.js"></script>
	<script type="text/javascript" src="/js/angular/angular.extend.js"></script>
	<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.js"> </script>
	<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"> </script>
	
	<style type="text/css">
	    div{
	        width:100%;
	    }
	</style>
</@head>

<body ng-app='app'>
<div class="container-fluid"  ng-controller="IntroController">
	<div class="row-fluid">
			<div class="span12">
				<h3 class="page-title">公司介绍</h3>
				<ul class="breadcrumb">
					<li>
						<i class="icon-home"></i>
						<a>基本信息</a> 
						<i class="icon-angle-right"></i>
					</li>
					<li>
						<a>编辑</a>
					</li>
				</ul>
			</div>
	</div>
	<div class="clearfix"></div>
	<!-- BEGIN PAGE BODY-->
 	<div class="row-fluid">  	 		
 	
 		<div class="portlet box blue">
			<div class="portlet-title">
				<div class="caption"><i class="icon-user"></i>编辑</div>
			</div>
			<div class="portlet-body">					
				<!-- BEGIN FORM-->
					<form class="form-horizontal" name="conForm" action="admin/com/intro/edit" method="post">
						
						<div class="control-group">
							<label class="control-label" style="width:100px;">标题<span class="required">*</span> ：</label>
								<div class="controls" style="margin-left:120px;">
								<input type="text" name="comName" ng-model="data.title" required ng-maxlength="20">
								<label style="color:red;" ng-if="conForm.comName.$error.maxlength">品牌名称长度超过20位</label>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" style="width:100px;">详细内容<span class="required"></span> ：</label>
								<div class="controls" style="margin-left:120px;" ng-model="data.info">
								<script id="editor" name="info" type="text/plain" style="width:800px;height:500px;"></script>
							</div>
						</div>
						<div class="control-group">
						    <div class="controls">
						      <button type="submit" class="btn blue">保存</button>
						      <a href="gtype/list" class="btn" style="margin-left:20px;">取消</a>
						    </div>
						  </div>
					  </form>    
			</div>	
		</div> 		
 		
 	</div>
 	<!-- END PAGE BODY-->
	<div class="clearfix"></div>
</div>
<div id="add_img" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h3 id="myModalLabel">选择图片</h3>
  </div>
  <div class="modal-body">
    <div class="tabbable" id="tabs-607659">
		<ul class="nav nav-tabs">
			<li class="active">
				<a href="#panel-629546" data-toggle="tab">本地上传</a>
			</li>
			<li>
				<a href="#panel-769134" data-toggle="tab">网络图片</a>
			</li>
		</ul>
		<div class="tab-content">
			<div class="tab-pane active" id="panel-629546">
			  <form id="local_form" class="form-horizontal" enctype="multipart/form-data" onSubmit="return false;">
			    <div class="control-group">
			      <label style="display:inline;margin-right:20px;">上传图片</label>
			      <input id="local_img" type="file" name="local_img" style="width:300px;"/>
			    </div>
			  </form>
			  <div class="text-right" style="border-top:1px solid #DDD;padding-top:20px;">
			    <button class="btn blue" ng-click="uploadImg()">确定</button>
			    <button id="l_close" class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
			  </div>
			</div>
			<div class="tab-pane" id="panel-769134">
			  <form id="web_form" class="form-horizontal" enctype="multipart/form-data" onSubmit="return false;">
				  <div class="control-group">
				      <label style="display:inline;margin-right:20px;">图片地址</label>
				      <input type="text" placeholder="图片地址" id="web_img" name="web_img" required"/>
				      <#--<label class="btn green" style="display:inline;margin-left:2px;">空间图片</label>-->
				  </div>
				</form>
				<div class="text-right" style="border-top:1px solid #DDD;padding-top:20px;">
				    <button class="btn blue" ng-click="uploadWebImg()">确定</button>
				    <button id="w_close" class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
			  </div>
			</div>
			<input id='img_addr' type='hidden'>
			
		</div>
	</div>
    
  </div>
</div>

<@plugin/>
	<script type="text/javascript" src="media/js/app.js" ></script>
<script>
var ue = UE.getEditor('editor');
var lang = ue.getOpt('lang');

var app = angular.module('app', []);

app.controller('IntroController', function($scope,$http){	

	
	<#if comInfo?exists>
		$scope.data=${comInfo};
	<#else>
		$scope.data={};
	</#if>
	$scope.save=function(){
			if ($scope.conForm.$pristine) {
				alert("请修改后再保存！");
				return;
			}
			if ($scope.conForm.$invalid) {
				alert("请输入正确的设置内容！");
				return;
			}
			
		};
	$scope.uploadWebImg = function() {
		var webImg = $("#web_img").val();
		if (!webImg) {
			alert("请填写图片URL");
			return;
		}
		$.getJSON("admin/com/intro/uploadWebImg?key=msg", {web_img: webImg}, function(data){
			if (data.status == 1) {
				var src = data.src;
				var id = $("#img_addr").data("id");
				$("#" + id + "_id").attr("src", data.fileUrl);
				$("#" + id).val(data.fileName);
				$("#l_close").click();
				
				$scope.$apply(function(){
					$scope.cover = data.fileName;
				});
				
			}else {
				alert(data.info);
			}
		});
	}
	
		$scope.uploadImg = function(){
		var file = $("#local_img").val();
		if (!file) {
			alert('请选择要上传的图片!');
			return;
		}
		
		$.ajaxFileUpload({  
	        url: "admin/com/intro/uploadImg?key=msg",  
	        secureuri: false,  
	        fileElementId: "local_img",         
	        dataType: "json",                  
	        success: function(data, status){  
	           if (data.status == 1) {
					var src = data.src;
					var id = $("#img_addr").data("id");
					$("#" + id + "_id").attr("src", data.fileUrl);
					$("#" + id).val(data.fileName);
					$("#l_close").click();
					
					$scope.$apply(function(){
						$scope.cover = data.fileName;
					});
				}else {
					alert(data.info);
				}
	        }  
	    });
	}
});
</script>
</body>
</@html>